using System.Collections;
using Holoville.HOTween;
using Holoville.HOTween.Core;
using I2.Loc;
using UnityEngine;

public class LeaderHUD : MonoBehaviour
{
	[SerializeField]
	private UILabel labeltText;

	private Vector3 startPos;

	private PlayerBehavior cLeader;

	private IEnumerator _show;

	private bool showing = true;

	public void Start()
	{
		labeltText.alpha = 0f;
		startPos = labeltText.transform.position;
		labeltText.transform.position = startPos + Vector3.up * 0.2f;
		HOTween.Init();
	}

	public void NewLeader(PlayerBehavior leader)
	{
		if (_show != null)
		{
			StopCoroutine(_show);
		}
		cLeader = leader;
		_show = Show();
		CoroutineRunner.Instance.StartCoroutine(_show);
	}

	private IEnumerator Show()
	{
		while (labeltText.alpha != 0f)
		{
			yield return null;
		}
		labeltText.text = string.Format(ScriptLocalization.Get("Game_Common/become_leader"), cLeader.Nick);
		HOTween.Kill(labeltText);
		HOTween.To(labeltText, 0.5f, new TweenParms().Prop("alpha", 1).OnComplete((TweenDelegate.TweenCallback)delegate
		{
		}));
		HOTween.To(labeltText.transform, 0.5f, new TweenParms().Prop("position", startPos).OnComplete((TweenDelegate.TweenCallback)delegate
		{
		}));
		yield return new WaitForSeconds(5f);
		Hide();
	}

	private void Hide()
	{
		if (labeltText != null)
		{
			HOTween.To(labeltText, 0.3f, new TweenParms().Prop("alpha", 0).OnComplete((TweenDelegate.TweenCallback)delegate
			{
			}));
			HOTween.To(labeltText.transform, 0.3f, new TweenParms().Prop("position", startPos + Vector3.up * 0.2f).OnComplete((TweenDelegate.TweenCallback)delegate
			{
			}));
		}
	}
}
